package cn.edu.scau.cmi.dengshixin.composite.consistent;

import java.util.ArrayList;

import cn.edu.scau.cmi.dengshixin.composite.Component;
import javafx.scene.control.TextArea;

public class ConsistentComposite extends Component {
	
private ArrayList<Component> children = new ArrayList<Component>();
	
	public ConsistentComposite(String name) {
		this.name = name;
		this.organization = null;
	}
	
	public ConsistentComposite(String name, String organization) {
		this.name = name;
		this.organization = organization;
	}
	
	public void doSomething(TextArea textArea) {
		if(name != null) {
			textArea.appendText("我们是[" + this.name + "]部门！\n");
			if(this.organization != null) {
				textArea.appendText("隶属于[" + this.organization + "]部门！\n");
			}
			else {
				textArea.appendText("\n");
			}
		}
		for(Component child : children) {
			child.doSomething(textArea);
		}
	}
	
	public boolean addChild(Component c) {
		return children.add(c);
	}
	
	public boolean removeChild(Component c) {
		return children.remove(c);
	}	

	public ArrayList<Component> getChildren() {
		return children;
	}

	public void setChildren(ArrayList<Component> children) {
		this.children = children;
	}
}
